/**
 * 所属节点：基础配置列表
 * 创建人：liud
 * 创建时间：2020年10月29日
 * 最后修改人：liud
 */
cb.define(process.env.__DOMAINKEY__, function () {
  let GDGY01_isv_appconfigList_VM_Extend = {
    doAction: function (name, viewModel) {
      if (this[name]) this[name](viewModel);
    },
    init: function (viewModel) {
      viewModel.on("customInit", function (data) {
        //基础配置列表--页面初始化

        //获取查询区模型
        var gridModel = viewModel.get("isv_appconfig_2053282732091899968");
        gridModel._set_data("forbiddenDblClick", true);
        // gridModel.setState('showCheckBox', false);
        gridModel.setState("showRowNo", true);

        //afterSetDataSource界面加载完成后，对数据进行修改afterStateRuleRunGridActionStates
        gridModel.on("afterSetDataSource", () => {
          //获取列表所有数据
          const rows = gridModel.getRows();
          //从缓存区获取按钮
          const actions = gridModel.getCache("actions");
          if (!actions) return;
          const actionsStates = [];
          rows.forEach((data) => {
            const level = data.appType;
            const actionState = {};
            actions.forEach((action) => {
              //设置按钮可用不可用
              if (level === 0) {
                actionState[action.cItemName] = { visible: false };
                // if (action.cItemName == 'btnDelete') {
                //     actionState[action.cItemName] = { visible: false };
                // }
                // else if (action.cItemName == 'btnEdit') {
                //     actionState[action.cItemName] = { visible: true };
                // }
              } else {
                actionState[action.cItemName] = { visible: true };
              }
              // actionState['btnCopy'] = { visible: false };
            });
            actionsStates.push(actionState);
          });
          gridModel.setActionsState(actionsStates);
          // console.log("level", actionsStates)
          // 按钮更新不生效 延迟更新状态
          setTimeout(function () {
            gridModel.setActionsState(actionsStates);
          }, 100);
        });
      });
      viewModel.getGridModel("isv_appconfig_2053282732091899968") &&
        viewModel.getGridModel("isv_appconfig_2053282732091899968").on("beforeSetDataSource", function (data) {
          //表格--设置数据源前
        });
    },
  };
  try {
    module.exports = GDGY01_isv_appconfigList_VM_Extend;
  } catch (error) {}
  return GDGY01_isv_appconfigList_VM_Extend;
});
